<template>
  <div class="app-container">
    <el-form :inline="true" :model="schoolNotice" class="demo-form-inline">
      <el-form-item label="标题">
        <el-input
          v-model="schoolNotice.title"
          placeholder="请输入标题"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getList">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="bclassList" :row-class-name="tableRowClassName">
      <el-table-column label="标题" align="center" prop="title" :show-overflow-tooltip="true" >
        <template slot-scope="scope">
            <el-link type="primary" @click="dianj(scope.row)">{{scope.row.title}}</el-link>
        </template>
      </el-table-column>
      <el-table-column label="发布范围" align="center" prop="releaseScopeNotice" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span v-if="scope.row.releaseScopeNotice == 1">班级</span>
          <span v-if="scope.row.releaseScopeNotice == 2">年级</span>
          <span v-if="scope.row.releaseScopeNotice == 3">全校</span>
        </template>
      </el-table-column>
      <el-table-column label="通知类型" align="center" prop="noticeType" :show-overflow-tooltip="true" >
        <template slot-scope="scope">
          <span v-if="scope.row.noticeType == 0">学工通知</span>
          <span v-if="scope.row.noticeType == 1">安全通知</span>
          <span v-if="scope.row.noticeType == 2">违纪通知</span>
        </template>
      </el-table-column>
      <el-table-column label="发布时间"  align="center" prop="createTime" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否已读" align="center" prop="status" :show-overflow-tooltip="true" >
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status == 1" type="success">已读</el-tag>
          <el-tag v-if="scope.row.status == 0" type="info">未读</el-tag>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="schoolNotice.pageNum"
      :limit.sync="schoolNotice.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改参数配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="50%" >
      <el-form ref="form" :model="xqList" label-width="100px" v-loading="dialogLoading">
        <el-row>
          <el-col :span="12">
            <el-form-item label="标题" prop="title">
              <span>{{xqList.title}}</span>
            </el-form-item>
          </el-col>
             <el-col :span="12">
            <el-form-item label="发布时间" prop="modifyTime">
                <span>{{ parseTime(xqList.modifyTime) }}</span>
            </el-form-item>
          </el-col>
        </el-row>
          <el-form-item label="通知内容" prop="noticeContent">
            <div v-html="xqList.noticeContent"></div>
          </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
  
  <script>
import { selfSchoolNotice, getNoticeSchool,readyNotice } from "@/api/notice/schoolNotice";
export default {
  name: "BClass",
  data() {
    return {
      cxForm: {
        title: null,
      },
      dialogLoading:false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      stuCount: 0,
      // 字典表格数据
      bclassList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 班主任
      userOptions: [],
      // 状态数据字典
      statusOptions: [],
      // 班级所属部门
      classDeptOptions: [],
      // 查询参数
      schoolNotice: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {
        sex: "1",
      },
      selectedList: [],
      isUpdate: false,
      xqList: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    tableRowClassName({row, rowIndex}) {
        if (row.status == 0) {
          return 'warning-row';
        } 
        return '';
    },
    onSubmit() {
      this.loading = true;
      findNoticeSchoolPageList(this.schoolNotice).then((res) => {
        console.log(res);
        this.bclassList = res.data.list;
        this.total = res.data.total;
        this.loading = false;
      });
    },
    /** 查询班级列表 */
    getList() {
      this.loading = true;
      console.log(this.schoolNotice);
      selfSchoolNotice(this.schoolNotice).then((response) => {
        console.log(response);
        this.bclassList = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    dianj(row) {
      console.log(row);
      this.open = true;
      this.dialogLoading = true
      getNoticeSchool(row.id).then(resp=>{
        this.xqList=resp.data
        const context = resp.data.noticeContent.replace(/<img/gi,"<img width='100%'")
        this.xqList.noticeContent = context
        this.dialogLoading = false
      })
      row.status=1
      readyNotice({id:row.id}).then(resp=>{
      })
      

    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        locationPid: 0,
        locationName: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.schoolNotice.pageNum = 1;
      if (this.schoolNotice.locationName) {
        this.schoolNotice.locationPid = null;
      } else {
        this.schoolNotice.locationPid = 0;
      }

      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");

      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd(row) {
      this.reset();
      this.open = true;
      this.title = "添加空间位置";
      this.form.locationPid = Number(row.id);
      this.disabledInput = false;
      this.isUpdate = false;
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.open = true;
      this.isUpdate = true;
      this.form = row;
      this.form.locationPid = Number(row.locationPid);
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          addjob(this.form).then((response) => {
            if (response.code === 200) {
              this.msgSuccess("提交成功");
              this.open = false;
              this.getList();
            } else {
              this.msgError(response.message);
            }
          });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      const param = {
        jobClassName: row.jobName,
        jobGroupName: row.jobGroupName,
      };
      this.$confirm('是否确认删除"' + row.jobName + '"任务吗?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return deletejob(param);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(function () {});
    },
    handlePause(row) {
      //暂停
      const param = {
        jobClassName: row.jobName,
        jobGroupName: row.jobGroupName,
      };
      pausejob(param).then((resp) => {
        this.msgSuccess("暂停成功");
        this.getList();
      });
    },
    handleResume(row) {
      //恢复
      const param = {
        jobClassName: row.jobName,
        jobGroupName: row.jobGroupName,
      };
      resumejob(param).then((resp) => {
        this.msgSuccess("暂停成功");
        this.getList();
      });
    },
  },
};
</script>
<style>
 .el-table .warning-row {
    background: oldlace;
  }
</style>
